home *** CD-ROM | disk | FTP | other *** search
Wrap
(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=ScorEpioN Title=Amazon.fr Description=RΘcupΦre les informations DVD d'Amazon.fr Site=http://www.amazon.fr Language=FR Version=11 du 23/05/2005 Requires=3.5 Comments=Ce script nΘcessite le fichier ScorEpioNCommonScript.pas|.==.| : ' ( ( ( ( /\ | "==()))))): ⌐ ScorEpioN ⌐| ( ( ( ( \_/ License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | GetInfo=1 [Options] Mise α jour=1|1|0=Oui|1=Non Type de Lancement=0|0|0=Demande le titre avant de lancer le script|1=Ne demande pas le titre avant de lancer le script|2=Cherche le meilleur rΘsultat sans confirmation|3=Lancement automatique sur l'adresse web Casse Choisie=3|3|0=Titre et Nom en minuscule|1=Titre et Nom en majuscule|2=PremiΦre lettre en majuscule|3=PremiΦre lettre de chaque mot en majuscule Titre en double=0|0|0=Garde les titres originaux et traduits mΩme identiques|1=Garde les titres originaux si identiques|2=Garde les titres traduits si identiques Recherche sur le titre=0|0|0=Traduit|1=Original Fichier de log=1|1|0=Oui|1=Non ***************************************************) program Amazon_FR; uses ScorEpioNCommonScript; const VersionScript = '11 du 23/05/2005'; urlDomain = 'amazon.fr'; NomScript = 'AMAZON.FR'; AmazonUrl = 'http://www.amazon.fr/exec/obidos/ASIN/'; AmazonSearch = 'http://www.amazon.fr/exec/obidos/search-handle-url/index=dvd-fr&field-keywords='; timetosleep = 500; var MovieName, Address : string; i, premiereExecution: Integer; listeResultat: TStringList; //------------------------------------------------------------------------------ // RECUPERE LES RESULTATS AMAZON.FR //------------------------------------------------------------------------------ procedure imageAmazon(title : String); var adresseRecherche, Line : String; StartPos: Integer; begin PickTreeClear; adresseRecherche := AmazonSearch+UrlEncode(title); Line := GetPage(adresseRecherche); if pos('satisfaisante pour votre recherche sur', Line) > 0 then begin SetField(fieldChecked, ''); exit; end else if (pos('Sur ce DVD', Line) > 0) or (pos('Amazon.fr : DVD:', Line) > 0) then begin recupInfo(Line); end else if pos('résultats au total pour', Line) > 0 then begin StartPos := pos('résultats au total pour', Line); delete(Line, 1, StartPos); recupAmazon(Line, title); end; end; //------------------------------------------------------------------------------ // CREATION DE LA LISTE DE RESULTAT //------------------------------------------------------------------------------ procedure recupAmazon(Line, title : String); var StartPos : Integer; couple, titre, adresse : String; begin listeResultat := TStringList.Create; StartPos := pos('<a href=/exec/obidos/ASIN/', Line); delete(Line, 1, StartPos-1); repeat {*********************** Boucle DEBUT ***********************} StartPos := pos('<a href=/exec/obidos/ASIN/', Line); delete(Line, 1, StartPos+length('<a href=/exec/obidos/ASIN/')-1); {*********************** Boucle DEBUT ***********************} //ajoute les films listeResultat.Add(recupTitle(Line)+'|'+AmazonUrl+copy(Line,0,pos('qid', Line)-1)); {*********************** Boucle FIN ***********************} StartPos := pos('<a href=/exec/obidos/ASIN/', Line); {*********************** Boucle FIN ***********************} until (StartPos = 0); if (GetOption('Type de Lancement') = 0) or (GetOption('Type de Lancement') = 1) then begin PickTreeAdd('Films trouvΘs pour ' + title + ' :', ''); for i:=0 to listeResultat.Count-1 do begin couple := listeResultat.GetString(i); titre := copy(couple,0,pos('|',couple)-1); adresse := copy(couple,pos('|',couple)+1,length(couple)-1); PickTreeAdd(titre , adresse); end; if listeResultat.Count = 1 then begin recupInfo(adresse); exit; end; if (PickTreeExec(Address)=true) then recupInfo(Address); end else if (GetOption('Type de Lancement') = 2) then begin trouveTitle(title); end; end; //------------------------------------------------------------------------------ // RECUPERE LES INFOS //------------------------------------------------------------------------------ procedure recupInfo(Adresse : String); var Value, Value2, Line: String; StartPos: Integer; begin // Pour le mode Batch if (GetOption('Fichier de log') = 0) then beforeUpdate(); Value := copy(Adresse,0,4); if Value = 'http' then begin Line := GetPage(Adresse); end else begin line := Adresse; Adresse := AmazonUrl+findInfo('name="asin" value="', '">', Line,'0'); end; StartPos := pos('<b class="sans">', Line); delete(Line, 1, StartPos-1); // Jaquette DVD if CanSetPicture then GetPicture(recupImage(Line)); // Titre Traduit if CanSetField(fieldTranslatedTitle) then begin Value := formatTitre(findInfo('<b class="sans">', '</b>', Line,'0'),GetOption('Casse Choisie')); delete(Value, pos(' - ',Value), length(Value)); if (pos('(',Value) > 0) then delete(Value, pos('(',Value), length(Value)); MonSetField(fieldTranslatedTitle, Value); end; // Acteurs if CanSetField(fieldActors) then MonSetField(fieldActors, formatTitre(findInfo('Avec :', '<br>', Line,'0'),GetOption('Casse Choisie'))); // RΘalisateur if CanSetField(fieldDirector) then MonSetField(fieldDirector, formatTitre(findInfo('Réalisateur :', '<br>', Line,'0'),GetOption('Casse Choisie'))); // Date de parution if CanSetField(fieldYear) then begin Value := findInfo('Date de parution :', '<br>', Line,'0'); MonSetField(fieldYear, copy(Value,length(Value)-4,length(Value))); end; // Editeur if CanSetField(fieldProducer) then MonSetField(fieldProducer, findInfo('Éditeur :', '<br>', Line,'0')); // Line α partir de Zone et Formats son StartPos := pos('Zone et formats son :', Line); delete(Line, 1, StartPos-1); // Zone if CanSetField(fieldVideoFormat) then MonSetField(fieldVideoFormat, 'DVD '+findInfo('Zone :', '<BR>', Line,'0')); // Langue if CanSetField(fieldLanguages) then MonSetField(fieldLanguages, findInfo('Langues et formats sonores :', '<BR>', Line,'0')); // Sous-titre if CanSetField(fieldSubtitles) then MonSetField(fieldSubtitles, findInfo('Sous-titres :', '<br>', Line,'0')); // Line α partir de DΘtails de l'Θdition StartPos := pos('Détails', Line); delete(Line, 1, StartPos-1); // Titre Original if CanSetField(fieldOriginalTitle) then MonSetField(fieldOriginalTitle, findInfo('Titre Original :', '<br>', Line,'0')); // Line α partir de Bonus StartPos := pos('Bonus', Line); delete(Line, 1, StartPos-1); // Bonus if CanSetField(fieldComments) then begin Value := findInfo('Bonus :', ' ASIN', Line,'-1'); if Value <> '' then Value := 'Bonus :'+Value; MonSetField(fieldComments, Value); end; // Line α partir de Bonus StartPos := pos('Chroniques et points de vue', Line); delete(Line, 1, StartPos-1); // Synopsis if CanSetField(fieldDescription) then begin if pos('Liste complète des chroniques et points de vue',Line) <> 0 then begin StartPos := Pos('href=/exec/obidos/tg/detail',Line); delete(Line,1,StartPos+5); Value := copy(Line,1,Pos('/ref',Line)-1); Line := GetPage('http://www.amazon.fr/'+Value); end; Value := findInfo('Synopsis</i></b></span><br>', '</span>', Line,'-1'); if Value <> '' then Value := 'Synopsis :'+#13#10+Value+#13#10#13#10; Value2 := Value; Value := findInfo('Amazon.fr</i></b></span><br>', '</span>', Line,'-1')+findInfo('Amazon.fr </i></b></span><br>', '</span>', Line,'-1'); if Value <> '' then Value := 'Avis Amazon.fr :'+#13#10+Value; MonSetField(fieldDescription, Value2+Value); end; // Adresse Web if CanSetField(fieldURL) then SetField(fieldURL, Adresse); // Pour le mode Batch if (GetOption('Fichier de log') = 0) then afterUpdate(); // Affichage des titres si original et traduit identique titreDouble(GetOption('Titre en double')); end; //------------------------------------------------------------------------------ // RECUPERE L'ADRESSE DE L'IMAGE //------------------------------------------------------------------------------ function recupImage(Line : String) : String; var ImageAddress : String; StartPos: Integer; begin StartPos := pos('http://images-eu.amazon.com/images/P/', Line); delete(Line, 1, StartPos-1); ImageAddress := copy(Line, 0, pos('"', Line) - 1); ImageAddress := StringReplace(ImageAddress, 'THUMBZZZ', 'LZZZZZZZ'); result := ImageAddress; end; //------------------------------------------------------------------------------ // RECUPERE LE TITRE //------------------------------------------------------------------------------ function recupTitle(Line : String) : String; var title : String; StartPos: Integer; begin StartPos := pos('<b>', Line); delete(Line, 1, StartPos-1); title := copy(Line, 1, pos('</b></a>', Line)-1); HTMLRemoveTags(title); title := StringReplace(title, #13#10, ''); result := title; end; //------------------------------------------------------------------------------ // IMPORTE L'IMAGE AMAZON //------------------------------------------------------------------------------ procedure importAmazon(Line : String); var ImageAddress : String; StartPos: Integer; begin StartPos := pos('http://images-eu.amazon.com/images/P/', Line); delete(Line, 1, StartPos-1); ImageAddress := copy(Line, 0, pos('"', Line) - 1); ImageAddress := StringReplace(ImageAddress, 'THUMBZZZ', 'LZZZZZZZ'); Sleep(timetosleep); GetPicture(ImageAddress); end; //------------------------------------------------------------------------------ // SUPPRIME LES ACCENTS //------------------------------------------------------------------------------ function supprimeAccents(NomFilm : String) : String; begin NomFilm := supprimeLesAccents(NomFilm); delete(NomFilm, pos(' - ',NomFilm), length(NomFilm)); if (pos(', ',NomFilm) > 0) then delete(NomFilm, 1, pos(', ',NomFilm)+1); if (pos('(',NomFilm) > 0) then delete(NomFilm, pos('(',NomFilm), length(NomFilm)); if (pos(':',NomFilm) > 0) then delete(NomFilm, pos(':',NomFilm), length(NomFilm)); result := trim(NomFilm); end; //------------------------------------------------------------------------------ // COMPARE LE TITRE PASSE ET LE TITRE TROUVE //------------------------------------------------------------------------------ function compareTitle(titleAllo, title : String) : String; begin title := supprimeAccents(trim(AnsiLowerCase(title))); titleAllo := supprimeAccents(trim(AnsiLowerCase(titleAllo))); if (title = titleAllo) then begin result := 'OK'; end else begin result := 'KO'; end; end; //------------------------------------------------------------------------------ // TROUVE LE BON TITRE SI LE PREMIER N'EST PAS LE BON //------------------------------------------------------------------------------ procedure trouveTitle(title : String); var oK, couple, titre, adresse : String; begin for i:=0 to listeResultat.Count-1 do begin couple := listeResultat.GetString(i); titre := copy(couple,0,pos('|',couple)-1); adresse := copy(couple,pos('|',couple)+1,length(couple)-1); oK := compareTitle(title,titre); if oK = 'OK' then begin recupInfo(adresse); exit; end; end; listeResultat.Free; end; //------------------------------------------------------------------------------ // PROGRAMME PRINCIPAL //------------------------------------------------------------------------------ begin if CheckVersion(3,5,0) then begin if GetOption('Mise α jour') = 0 then begin execMenuMAJ(VersionScript,NomScript); exit; end; MovieName := recupTitreRecherche(GetOption('Recherche sur le titre')); if (GetOption('Fichier de log') = 0) and (premiereExecution = 0) then begin batch(NomScript); AddToLog('Les films ayant ΘtΘ mis α jour sont maintenant cochΘs'); end; if (GetOption('Type de Lancement') = 0) then begin if Input(NomScript+' by ScorEpioN', 'Entrez le titre du film :', MovieName) then begin if Pos(urlDomain, MovieName) > 0 then begin recupInfo(MovieName); end else imageAmazon(MovieName); end; end else if (GetOption('Type de Lancement') = 3) then begin if (premiereExecution = 0) then begin premiereExecution := -1; if (ShowConfirmation('Vous allez executer le script sans confirmation, cliquer sur ''''OUI'''' pour continuer') = False) then exit; end; MovieName := GetField(fieldURL); if Pos(urlDomain, MovieName) > 0 then recupInfo(MovieName); end else begin if (premiereExecution = 0) then begin premiereExecution := -1; if (ShowConfirmation('Vous allez executer le script sans confirmation, cliquer sur ''''OUI'''' pour continuer') = True) then begin imageAmazon(MovieName); end else exit; end else begin imageAmazon(MovieName); end; end; end else ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)'); end.